package reformat;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public String reformat(String s) {
        List<Character> chars = new ArrayList<>();
        List<Character> numbers = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            if(Character.isLetter(s.charAt(i))){
                chars.add(s.charAt(i));
            } else {
                numbers.add(s.charAt(i));
            }
        }
        if(Math.abs(chars.size()-numbers.size())>1){
            return "";
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < Math.max(numbers.size(),chars.size()); i++) {
            if(numbers.size()>chars.size()){
                if(i<numbers.size()){
                    sb.append(numbers.get(i));
                }
                if(i<chars.size()){
                    sb.append(chars.get(i));
                }
            } else {
                if(i<chars.size()){
                    sb.append(chars.get(i));
                }
                if(i<numbers.size()){
                    sb.append(numbers.get(i));
                }
            }
        }
        return sb.toString();
    }
}
